package com.alvis.media.viewmodel.video;

import com.alvis.media.domain.VideoInfo;
import com.alvis.media.utility.DateTimeUtil;
import com.alvis.media.viewmodel.BaseVM;
import lombok.Data;


@Data
public class VideoResponseVM extends BaseVM {

    private Integer videoId;



    private String videoName;


    private Integer videoCategory;

    private String createTime;

    private Integer creatorId;

    private String lastModifyTime;

    private String videoUrl;


    public static VideoResponseVM from(VideoInfo videoInfo) {
        VideoResponseVM vm = modelMapper.map(videoInfo, VideoResponseVM.class);
        vm.setLastModifyTime(DateTimeUtil.dateFormat(videoInfo.getLastModifyTime()));
        vm.setCreateTime(DateTimeUtil.dateFormat(videoInfo.getCreateTime()));
        
        // 将视频路径转换为完整的API路径
        if (videoInfo.getVideoUrl() != null && !videoInfo.getVideoUrl().trim().isEmpty()) {
            String videoUrl = videoInfo.getVideoUrl().trim();
            String apiPath;
            
            // 优化视频URL处理逻辑
            if (videoUrl.startsWith("/api/video/play/")) {
                // 如果已经是正确的API路径格式，保持不变
                apiPath = videoUrl;
            } else if (videoUrl.startsWith("D:")) {
                // 如果路径是D盘路径，使用基础的play接口路径
                // 确保路径分隔符正确处理
                apiPath = "/api/video/play/" + videoUrl;
            } else if (videoUrl.startsWith("20")) {
                // 如果路径是以日期开头的文件名，假设文件在D:\VideoVideoUpload目录下
                apiPath = "/api/video/play/D:VideoVideoUpload/" + videoUrl;
            } else {
                // 默认情况，构建标准的API路径格式
                apiPath = "/api/video/play/D:VideoVideoUpload/" + videoUrl;
            }
            
            vm.setVideoUrl(apiPath);
        }
        
        return vm;
    }
}
